<%@page import="org.siscoh.model.dao.CategoriaDao"%>
<%@page import="org.siscoh.model.bean.CategoriaBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    /*
    request.setAttribute("minper", 1);
    
    if(!ControlePermissao.possuiPermissao(request, response))
    {
        return;
    }*/
%>
<html>
  <head>
    <title>Busca de peça</title>
    
    <script type="text/javascript" language="javascript" src="script/jquery.min.js" ></script>
    <script type="text/javascript" language="javascript" src="script/jquery.blockUI.js" ></script>
    <script>
        function search()
        {
            var pesquisa = $("#pesquisa").val();
            
            if(pesquisa == null || pesquisa == "")
            {
                return;
            }
            
            var width = ($(document).width() - 32)/2;
            $.blockUI({ message: '<img src="imagens/icones/ajax-loader.gif" />',
                        css: {width:'32px', height:'32px', border: 'none', left: width+'px' }
                     }
            );
            
            var categId = $("#categoria option:selected").val();
            
            $.ajax({
                type:"POST",
                url:"AjaxController",
                data: {action:"2", categoria: categId, input: pesquisa},
                success:
                    function(resposta)
                    {
                        $("#pecastable").html(resposta);
                        $.unblockUI();
                    },
                error:
                    function()
                    {
                        $.unblockUI();
                        setTimeout("alert('Erro ao carregar.\nPor favor tente novamente.')", 1000);
                    }
            });
            
            $.unblockUI();
        }
    </script>
    
  </head>
  
<body bgcolor='gray'>
  <!--<div style="border: 1px solid black; width: 120px; padding: 0px; margin: 0px; ">-->
<br>

<%
    CategoriaBean catList[] = (CategoriaBean[]) new CategoriaDao().fetchAll();
    //new CategoriaDao().fe
    request.setAttribute("categorias", catList);
%>

<div align="center">
<table id="todoform" cellspacing="5" rules="" border="0">
    <tr>
        <td colspan="4" bgcolor="">
            <div id="" align="center">Consulta de Peças</div>
        </td>
        <td></td>
    </tr>        
    <tr>
      <td>Pesquisa:</td>
      <td><input id="pesquisa" name='pesquisa' id='pesquisa' type='text' maxlength='50' size='50' onkeypress=""></td>
      <td>
          <select id="categoria" name="categoria">
              <option value="-1" >Todas as categorias</option>
              <c:forEach items="${categorias}" var="categ">
                  <option value="${categ.id}">${categ.nome}</option>
              </c:forEach>
          </select>
      </td>
      <td><input type="image" id="imagem" src="imagens/icones/pesquisa.png" title="pesquisa" onClick="search()" /></td>
    </tr>  
  </table>

<table id="pecastable" name="pecastable" width="90%" cellspacing="5" rules="" border="0">
    
</table>
</div>
</body>
</html>